home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / ROTATE.C < prev    next >
C/C++ Source or Header  |  1992-07-10  |  15KB  |  464 lines

  1. /*
  2.     rotate.c - Routines that manipulate the Video DAC on VGA Adapters
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #include "fractint.h"
  11. #include "helpdefs.h"
  12. #include "prototyp.h"
  13.  
  14. /* routines in this module    */
  15.  
  16. static void pauserotate(void);
  17. static void set_palette(),set_palette2(),set_palette3();
  18.  
  19. extern char temp1[];
  20.  
  21. extern    int    colors;         /* maximum colors available */
  22.  
  23. extern BYTE dacbox[256][3];    /* Video-DAC (filled in by SETVIDEO) */
  24. extern    int    gotrealdac;        /* dacbox valid? */
  25. extern BYTE olddacbox[256][3];
  26. extern int    daclearn, daccount;    /* used by the color-cyclers */
  27. extern int    reallyega;        /* == 0 if it's really an EGA */
  28. extern int    rotate_lo,rotate_hi;    /* range of colors to cycle */
  29. extern int    colorstate; /* comments in cmdfiles */
  30. extern char    colorfile[];
  31. extern int    dotmode;
  32.  
  33. static int paused;            /* rotate-is-paused flag */
  34.  
  35. static BYTE Red[3]    = {63, 0, 0};    /* for shifted-Fkeys */
  36. static BYTE Green[3]  = { 0,63, 0};
  37. static BYTE Blue[3]   = { 0, 0,63};
  38. static BYTE Black[3]  = { 0, 0, 0};
  39. static BYTE White[3]  = {63,63,63};
  40. static BYTE Yellow[3] = {63,63, 0};
  41. static BYTE Brown[3]  = {31,31, 0};
  42.  
  43. char mapmask[13] = {"*.map"};
  44.  
  45.  
  46. void rotate_overlay() { }    /* for restore_active_ovly */
  47.  
  48. void rotate(int direction)    /* rotate-the-palette routine */
  49. {
  50. int  kbdchar, more, last, next;
  51. int fkey, step, fstep, istep, jstep, oldstep;
  52. int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
  53. int i, changecolor, changedirection;
  54. int oldhelpmode;
  55. int rotate_max,rotate_size;
  56.  
  57. static int fsteps[] = {2,4,8,12,16,24,32,40,54,100}; /* (for Fkeys) */
  58.  
  59.    ENTER_OVLY(OVLY_ROTATE);
  60.  
  61.    if (gotrealdac == 0            /* ??? no DAC to rotate! */
  62.      || colors < 16) {            /* strange things happen in 2x modes */
  63.       buzzer(2);
  64.       EXIT_OVLY;
  65.       return;
  66.       }
  67.  
  68.    oldhelpmode = helpmode;        /* save the old help mode    */
  69.    helpmode = HELPCYCLING;        /* new help mode        */
  70.  
  71.    paused = 0;                /* not paused            */
  72.    fkey = 0;                /* no random coloring        */
  73.    oldstep = step = 1;            /* single-step            */
  74.    fstep = 1;
  75.    changecolor = -1;            /* no color (rgb) to change    */
  76.    changedirection = 0;         /* no color direction to change */
  77.    incr = 999;                /* ready to randomize        */
  78.    srand((unsigned)time(NULL));     /* randomize things        */
  79.  
  80.    if (direction == 0) {        /* firing up in paused mode?    */
  81.       pauserotate();            /* then force a pause        */
  82.       direction = 1;            /* and set a rotate direction    */
  83.       }
  84.  
  85.    rotate_max = (rotate_hi < colors) ? rotate_hi : colors-1;
  86.    rotate_size = rotate_max - rotate_lo + 1;
  87.    last = rotate_max;            /* last box that was filled    */
  88.    next = rotate_lo;            /* next box to be filled    */
  89.    if (direction < 0) {
  90.       last = rotate_lo;
  91.       next = rotate_max;
  92.       }
  93.  
  94.    more = 1;
  95.    while (more) {
  96.       if (dotmode == 11) {
  97.      if (!paused)
  98.         pauserotate();
  99.      }
  100.       else while(!keypressed()) { /* rotate until key hit, at least once so step=oldstep ok */
  101.      if (fkey > 0) {        /* randomizing is on */
  102.         for (istep = 0; istep < step; istep++) {
  103.            jstep = next + (istep * direction);
  104.            while (jstep < rotate_lo)  jstep += rotate_size;
  105.            while (jstep > rotate_max) jstep -= rotate_size;
  106.            if (++incr > fstep) {    /* time to randomize */
  107.           incr = 1;
  108.                   fstep = ((fsteps[fkey-1]* (rand15() >> 8)) >> 6) + 1;
  109.           fromred   = dacbox[last][0];
  110.           fromgreen = dacbox[last][1];
  111.           fromblue  = dacbox[last][2];
  112.                   tored     = rand15() >> 9;
  113.                   togreen   = rand15() >> 9;
  114.                   toblue    = rand15() >> 9;
  115.           }
  116.            dacbox[jstep][0] = fromred   + (((tored     - fromred  )*incr)/fstep);
  117.            dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  118.            dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  119.            }
  120.         }
  121.      if (step >= rotate_size) step = oldstep;
  122.      spindac(direction, step);
  123.      }
  124.       if (step >= rotate_size) step = oldstep;
  125.       kbdchar = getakey();
  126.       if (paused && (kbdchar != ' ' && kbdchar != 'c' && kbdchar != 'C' ))
  127.      paused = 0;            /* clear paused condition    */
  128.       switch (kbdchar) {
  129.      case '+':                      /* '+' means rotate forward     */
  130.          case RIGHT_ARROW:              /* RightArrow = rotate fwd      */
  131.         fkey = 0;
  132.         direction = 1;
  133.         last = rotate_max;
  134.         next = rotate_lo;
  135.         incr = 999;
  136.         break;
  137.      case '-':                      /* '-' means rotate backward    */
  138.          case LEFT_ARROW:               /* LeftArrow = rotate bkwd      */
  139.         fkey = 0;
  140.         direction = -1;
  141.         last = rotate_lo;
  142.         next = rotate_max;
  143.         incr = 999;
  144.         break;
  145.          case UP_ARROW:                 /* UpArrow means speed up       */
  146.         daclearn = 1;
  147.         if (++daccount >= colors) --daccount;
  148.         break;
  149.          case DOWN_ARROW:               /* DownArrow means slow down    */
  150.         daclearn = 1;
  151.         if (daccount > 1) daccount--;
  152.         break;
  153.      case '1':
  154.      case '2':
  155.      case '3':
  156.      case '4':
  157.      case '5':
  158.      case '6':
  159.      case '7':
  160.      case '8':
  161.      case '9':
  162.         step = kbdchar - '0';   /* change step-size */
  163.         if (step > rotate_size) step = rotate_size;
  164.         break;
  165.          case F1:                       /* F1 - F10:                    */
  166.          case F2:                       /* select a shading factor      */
  167.          case F3:
  168.          case F4:
  169.          case F5:
  170.          case F6:
  171.          case F7:
  172.          case F8:
  173.          case F9:
  174.          case F10:
  175. #ifndef XFRACT
  176.             fkey = kbdchar-1058;
  177. #else
  178.             switch (kbdchar) {
  179.                case F1:
  180.                   fkey = 1;break;
  181.                case F2:
  182.                   fkey = 2;break;
  183.                case F3:
  184.                   fkey = 3;break;
  185.                case F4:
  186.                   fkey = 4;break;
  187.                case F5:
  188.                   fkey = 5;break;
  189.                case F6:
  190.                   fkey = 6;break;
  191.                case F7:
  192.                   fkey = 7;break;
  193.                case F8:
  194.                   fkey = 8;break;
  195.                case F9:
  196.                   fkey = 9;break;
  197.                case F10:
  198.                   fkey = 10;break;
  199.             }
  200. #endif
  201.         if (reallyega) fkey = (fkey+1)>>1; /* limit on EGA */
  202.         fstep = 1;
  203.         incr = 999;
  204.         break;
  205.          case ENTER:                    /* enter key: randomize all colors */
  206.          case ENTER_2:                  /* also the Numeric-Keypad Enter */
  207.             fkey = rand15()/3277 + 1;
  208.         if (reallyega)        /* limit on EGAs */
  209.            fkey = (fkey+1)>>1;
  210.         fstep = 1;
  211.         incr = 999;
  212.         oldstep = step;
  213.         step = rotate_size;
  214.         break;
  215.      case 'r':                      /* color changes */
  216.         if (changecolor    == -1) changecolor = 0;
  217.      case 'g':                      /* color changes */
  218.         if (changecolor    == -1) changecolor = 1;
  219.      case 'b':                      /* color changes */
  220.         if (changecolor    == -1) changecolor = 2;
  221.         if (changedirection == 0) changedirection = -1;
  222.      case 'R':                      /* color changes */
  223.         if (changecolor    == -1) changecolor = 0;
  224.      case 'G':                      /* color changes */
  225.         if (changecolor    == -1) changecolor = 1;
  226.      case 'B':                      /* color changes */
  227.         if (dotmode == 11) break;
  228.         if (changecolor    == -1) changecolor = 2;
  229.         if (changedirection == 0) changedirection = 1;
  230.         if (reallyega) break;    /* no sense on real EGAs */
  231.         for (i = 1; i < 256; i++) {
  232.            dacbox[i][changecolor] += changedirection;
  233.            if (dacbox[i][changecolor] == 64)
  234.            dacbox[i][changecolor] = 63;
  235.            if (dacbox[i][changecolor] == 255)
  236.           dacbox[i][changecolor] = 0;
  237.            }
  238.         changecolor    = -1;    /* clear flags for next time */
  239.         changedirection = 0;
  240.         paused        = 0;    /* clear any pause */
  241.      case ' ':                      /* use the spacebar as a "pause" toggle */
  242.      case 'c':                      /* for completeness' sake, the 'c' t